import { getDB } from '../../db';

/**
 * 添加视频标注 支持批量添加
 */
export const createAddMarkInfoStatement = () => {
  const db = getDB();
  return db.prepare<[LX.DBService.MarkInfoInfo]>(`
      INSERT INTO "main"."video_mark_info" ("id","video_info_id","start_time","end_time","label","describe","channel","status","create_time","create_user")
      values(@id,@videoInfoId,@startTime,@endTime,@label,@describe,@channel,@status,@createTime,@createUser)`);
};

/**
 * 时间标记与标注  标注条件查询  -> 同视频录制与编辑
 */

//  时间标记与标注   导出标注/查询所有标注列表 [实时标注+标注]

/**
 * 时间标记与标注   导出标注列表/多路视频标注 右侧列表 [实时标注]
 */

export const videoRealMarkListByVedioIdStatement = () => {
  const db = getDB();
  let query = `
 SELECT
	v.id as v_id,v."start_time" as v_start_time, v."end_time"  as v_end_time, v."channel" as v_channel,
	m."id",m."start_time",m."end_time",m."label",m."describe",m."create_time", 2 type
FROM
	video_info v
	JOIN video_real_mark_info m ON m.start_time >= v.start_time
	AND m.start_time <= v.end_time and m.status = 0 and v.channel = m.channel and v.id = ?
  order by cast(m.start_time as double)
`;
  return db.prepare<[String]>(query);
};

/**
 * 时间标记与标注   导出标注列表/多路视频标注 右侧列表 [标注]
 */
export const videoMarkListByVedioIdStatement = () => {
  const db = getDB();
  let query = `
    select
      v.id as v_id,v."start_time" as v_start_time, v."end_time"  as v_end_time, v."channel" as v_channel,
      m."id",m."start_time",m."end_time",m."label",m."describe",m."create_time", 1 type
    from video_info v
        join video_mark_info m  on v.id = m.video_info_id and m.status = 0 where m."video_info_id" = ?
        order by cast(m.start_time as double)
    `;
  return db.prepare<[String]>(query);
};

/**
 * 删除视频标注
 */
export const videoMarkDeleteStatement = () => {
  const db = getDB();
  return db.prepare<[LX.DBService.VideoMarkUpdate]>(
    'UPDATE "main"."video_mark_info"  set "status" = @status where "id" = @id',
  );
};

/*获取最大id*/
export const getMaxId = () => {
  const db = getDB();
  return db.prepare<[], LX.DBService.MarkInfoMaxId>(`SELECT max(cast(id as int)) id FROM "video_mark_info" `);
};
